<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('获取时间')">
              <a-date-picker
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></a-date-picker>
              <span class="query-group-split-cust"></span>
              <a-date-picker
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('票信息')">
              <a-input :placeholder="$t('请输入票号/票名称')" v-model="queryParam.ticketInfo"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input :placeholder="$t('请输入手机号/卡号/姓名')" v-model="queryParam.memberInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('最后消费时间')">
                <a-date-picker
                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择开始时间')"
                  class="query-group-cust"
                  v-model="queryParam.updateTime_begin"
                ></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker
                  :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择结束时间')"
                  class="query-group-cust"
                  v-model="queryParam.updateTime_end"
                ></a-date-picker>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="5" :md="6" :sm="24">
              <a-form-item :label="$t('票类型')">
                <a-select v-model="queryParam.form">
                  <a-select-option v-for="(item, index) in formList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="5" :md="6" :sm="24">
              <a-form-item :label="$t('状态')">
                <a-select v-model="queryParam.state">
                  <a-select-option v-for="(item, index) in stateList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('来源')">
                <a-select v-model="queryParam.source">
                  <a-select-option v-for="(item, index) in sourceList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('关联年月次票')">
                <a-input :placeholder="$t('请输入关联年月次票票号/名称')" v-model="queryParam.parentInfo"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="8" :lg="9" :md="10" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button 
      v-has="'BisMemberTicketController:export'"
        type="primary"
        icon="download"
        :loading="exloading"
        @click="handleExportXls($t('年票次票账户'))"
        >{{ $t('导出') }}</a-button
      >
      <a-button v-has="'BisMemberTicketController:import'" type="primary" icon="import" @click="importFile">{{ $t('导入') }}</a-button>
      <a-button type="primary" @click="validTotal()">{{ $t('门票汇总') }}</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">{{
            $t('下载')
          }}</a-button>
        </template>
        <template slot="name" slot-scope="text, record">
          <a @click="ViewMember(record)">{{ text }}</a>
        </template>
        <template slot="cardNo" slot-scope="text, record">
          <a @click="ViewMember(record)">{{ text }}</a>
        </template>
        <template slot="phone" slot-scope="text, record">
          <a @click="ViewMember(record)">{{ text }}</a>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-has="'BisMemberTicketList:edit'" @click="handleEdit(record)">{{ $t('编辑') }}</a>
          <a-divider v-has="'BisMemberTicketList:edit'" type="vertical" />
          <a @click="handleRecord(record)">{{ $t('消费记录') }}</a>
        </span>
      </a-table>
    </div>
    <edit-member-ticket-modal ref="modalForm" @ok="modalFormOk"></edit-member-ticket-modal>
    <ticket-details-modal ref="ticketDetails"></ticket-details-modal>
    <!-- <bis-member-ticket-modal ref="modalForm" @ok="modalFormOk"></bis-member-ticket-modal> -->
    <import-member-ticket-modal ref="importModal" @ok="modalFormOk"></import-member-ticket-modal>
    <member-ticket-valid-total-modal ref="validTotal" @ok="modalFormOk"></member-ticket-valid-total-modal>
    <member-modal ref="member"></member-modal>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BisMemberTicketModal from './modules/BisMemberTicketModal'
import EditMemberTicketModal from './modules/EditMemberTicketModal'
import TicketDetailsModal from './modules/TicketDetailsModal'
import ImportMemberTicketModal from './modules/ImportMemberTicketModal'
import MemberTicketValidTotalModal from './modules/MemberTicketValidTotalModal'
import MemberModal from './modules/MemberModal'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'BisMemberTicketList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    /* BisMemberTicketModal, */
    EditMemberTicketModal,
    TicketDetailsModal,
    ImportMemberTicketModal,
    MemberTicketValidTotalModal,
    MemberModal,
  },
  data() {
    return {
      description: '年票次票账户管理页面',
      moment,
      // 表头
      columns: [
        {
          title: this.$t('票号'),
          align: 'center',
          dataIndex: 'ticketNo',
          sorter: true,
        },
        {
          title: this.$t('票名称'),
          align: 'center',
          dataIndex: 'goodsName',
          sorter: true,
        },
        {
          title: this.$t('票类型'),
          align: 'center',
          dataIndex: 'form_dictText',
          sorter: true,
        },
        {
          title: this.$t('总次数'),
          align: 'center',
          dataIndex: 'totalNumber',
          sorter: true,
          customRender: (text) => {
            if (text == 0) {
              return this.$t('不限次')
            } else {
              return text
            }
          },
        },
        {
          title: this.$t('剩余次数'),
          align: 'center',
          dataIndex: 'remainNumber',
          sorter: true,
          customRender: (text, record) => {
            if (record.totalNumber == 0) {
              return this.$t('不限次')
            } else {
              return text
            }
          },
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
          sorter: true,
        },
        {
          title: this.$t('有效期'),
          align: 'center',
          dataIndex: 'validityStart',
          sorter: true,
          customRender: (text, record) => {
            if (text == null) {
              return this.$t('不限期')
            } else if (text) {
              return record.validityStart + '~' + record.validityEnd
            } else {
              return this.$t('不限期')
            }
          },
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'memberPhone',
          sorter: true,
          scopedSlots: { customRender: 'phone' },
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
          sorter: true,
          scopedSlots: { customRender: 'cardNo' },
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'memberName',
          sorter: true,
          scopedSlots: { customRender: 'name' },
        },
        {
          title: this.$t('获取时间'),
          align: 'center',
          dataIndex: 'createTime',
          sorter: true,
        },
        {
          title: this.$t('来源'),
          align: 'center',
          dataIndex: 'source_dictText',
          sorter: true,
        },
        {
          title: this.$t('最后一次消费时间'),
          align: 'center',
          dataIndex: 'updateTime',
          sorter: true,
        },
        {
          title: this.$t('关联年月次票'),
          align: 'center',
          dataIndex: 'parentId_dictText',
          sorter: true,
        },
        {
          title: this.$t('操作列'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/member/bisMemberTicket/list',
        delete: '/member/bisMemberTicket/delete',
        deleteBatch: '/member/bisMemberTicket/deleteBatch',
        exportXlsUrl: '/member/bisMemberTicket/exportXls',
        importExcelUrl: 'member/bisMemberTicket/importExcel',
      },
      queryParam: {
        form: '',
        state: '',
        source: '',
      },
      dictOptions: {},
      formList: [],
      stateList: [],
      sourceList: [],
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_goods_infor.form').then((res) => {
        if (res.success) {
          this.formList = res.result.filter((r) => {
            return r.value == '3' || r.value == '4'
          })
          this.formList.unshift({ title: this.$t('全部'), value: '' })
        }
      })
      initDictOptions('bis_member_ticket.state').then((res) => {
        if (res.success) {
          this.stateList = res.result
          this.stateList.unshift({ title: this.$t('全部'), value: '' })
        }
      })
      initDictOptions('bis_member_ticket.source').then((res) => {
        if (res.success) {
          this.sourceList = res.result
          this.sourceList.unshift({ title: this.$t('全部'), value: '' })
        }
      })
    },
    importFile() {
      let that = this
      that.$refs.importModal.show()
    },
    searchReset() {
      this.queryParam = {
        form: '',
        state: '',
        source: '',
      }
      this.searchQuery(1)
    },
    handleRecord(record) {
      this.$refs.ticketDetails.edit(record)
    },
    validTotal() {
      this.$refs.validTotal.show()
    },
    ViewMember(record) {
      this.$refs.member.show(record)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>